import {useUserState} from "~/stores/pinia/useLoginfo";
import { ElNotification } from 'element-plus';
import { useRouter } from 'vue-router';


export default defineNuxtRouteMiddleware(async (to, from) => {
    const userState = useUserState()
    const router = useRouter();
    await userState.restoreFromLocalStorage();

    if (!userState.userinfo && to.path === '/about') {
        ElNotification({
            title: 'Warning',
            message: '请先登录账户！',
            type: 'warning',
            duration: 1000 // 持续时间，单位为毫秒
        });
        // 用户未登录，重定向到登录页
        return navigateTo('/login')
    }
})